unit TypInfoUtils;

interface

uses Classes, TypInfo;

function HasProperty(AComp: TComponent; APropName: String): boolean;
procedure SetStringProperty(AComp: TComponent; APropName: String;
  AValue: String);
function GetStringProperty(AComp: TComponent; APropName: String): String;

implementation

function HasProperty(AComp: TComponent; APropName: String): boolean;
begin
  result := GetPropInfo(AComp.ClassInfo, APropName) <> nil;
end;

procedure SetStringProperty(AComp: TComponent; APropName: String;
  AValue: String);
var
  PropInfo: PPropInfo;
  TK: TTypeKind;
begin
  PropInfo := GetPropInfo(AComp.ClassInfo, APropName);
  if PropInfo <> nil then
  begin
    TK := PropInfo^.PropType^.Kind;
    if (TK = tkString) or (TK = tkLString) or (TK = tkWString) then
      SetStrProp(AComp, PropInfo, AValue);
  end;
end;

function GetStringProperty(AComp: TComponent; APropName: String): String;
var
  PropInfo: PPropInfo;
  TK: TTypeKind;
begin
  PropInfo := GetPropInfo(AComp.ClassInfo, APropName);
  if PropInfo <> nil then
  begin
    TK := PropInfo^.PropType^.Kind;
    if (TK = tkString) or (TK = tkLString) or (TK = tkWString) then
      result := GetStrProp(AComp, PropInfo);
  end;

end;

end.
